
import type { EmpReqALogin, EmpReqELogin, EmpRspLogin, Positions, selectPositions, addPositionInfo, ApiResponse, EmpAdd, EmpReq,EmpRsp, Authority, DeptEmpRsp, EmpPositionRsp, PiVocations,Vocations, selectVocation, VocationReq, Attendance, AttendRsp, RetroactiveReq} from "../model"

import instance from "../utils/request"

export const loginA = (param: EmpReqALogin): Promise<{ emp: EmpRspLogin }> => {
  return instance({
    method: 'post',
    url: '/loginA',
    data: param
  })
}

export const loginE = (param: EmpReqELogin): Promise<{ emp: EmpRspLogin }> => {
  return instance({
    method: 'post',
    url: '/loginE',
    data: param
  })
}

export const resetPassword = (param: EmpReqELogin): Promise<String> => {
  return instance({
    method: 'post',
    url: '/resetPwd',
    data: param
  })
}

export const updatePassword = (newPwd: string): Promise<string> => {
  return instance({
    method: 'post',
    url: '/updatePwd',
    data: newPwd
  })
}

export const getPositions = (param: selectPositions): Promise<Positions> => {
  return instance({
    method: 'get',
    url: '/positions',
    params: param
  })
}
export const addPosition = (param: addPositionInfo): Promise<''> => {
  return instance({
    method: 'post',
    url: '/addposition',
    data: param
  })
}

export const modifyPosition = (param: addPositionInfo, no: number): Promise<''> => {
  return instance({
    method: 'post',
    url: '/modifyposition/' + no,
    data: param
  })
}
export const deletePosition = (no: number): Promise<''> => {
  return instance({
    method: 'delete',
    url: '/deleteposition/' + no,
    data: no
  })
}

export const selectEmp = (pageSize: number, pageNum: number, empReq: EmpReq): Promise<ApiResponse<EmpRsp[]>> => {
  return instance({
    method: 'put',
    url: '/getEmp',
    params: {
      pageSize,
      pageNum
    },
    data: empReq
  })
}

export const addOrUpdateEmp = (empAdd: EmpAdd): Promise<ApiResponse<EmpRsp>> => {
  return instance({
    method: 'post',
    url: '/insertOrUpdateEmp',
    data: empAdd
  })
}

export const getOneEmp = (id: number): Promise<ApiResponse<EmpAdd>> => {
  return instance({
    method: 'get',
    url: '/getOneEmp',
    params: {
      id
    }
  })
}

export const updateStatusEmp = (id: number): Promise<ApiResponse<number>> => {
  return instance({
    method: 'put',
    url: '/updateStatusEmp',
    params: {
      id
    }
  })
}

export const getAuthority = (): Promise<ApiResponse<Authority[]>> => {
  return instance({
    method: 'get',
    url: '/getAllAuthority'
  })
}

export const getDeptVocations = (param: selectVocation): Promise<Vocations> => {
  return instance({
    method: 'get',
    url: '/deptvocations',
    params: param
  })
}

export const requestVacation = (param: VocationReq): Promise<''> => {
  return instance({
    method: 'post',
    url: '/requestvocation',
    data: param
  })
}

export const getVocations = (param: selectVocation): Promise<Vocations> => {
  return instance({
    method: 'get',
    url: '/vocations',
    params: param
  })
}

export const getDeptEmp = (id: number): Promise<ApiResponse<DeptEmpRsp[]>> => {
  return instance({
    method: 'get',
    url: '/getEmpDept',
    params: {
      id
    }
  })
}

export const getPositionsEmp = (id: number): Promise<ApiResponse<EmpPositionRsp[]>> => {
  return instance({
    method: 'get',
    url: '/getEmpPosition',
    params: {
      id
    }
  })
}
export const updateVocationStatus = (param: PiVocations): Promise<''> => {
  return instance({
    method: 'post',
    url: "/updateVocationStatus",
    data: param
    
  })
}

export const getAttend = (startDate: string, endDate: string): Promise<ApiResponse<Attendance[]>> => {
  return instance({
    method: 'get',
    url: '/attendance/my-records',
    params: {
      startDate,
      endDate
    }
})}

export const addAttend = (type: number): Promise<ApiResponse<number>> => {
  return instance({
    method: 'post',
    url: '/attendance/in',
    data: {
      type
    }
  })
}

export const getAttends = (pageNum: number, pageSize: number): Promise<ApiResponse<AttendRsp[]>> => {
  return instance({
    method: 'get',
    url: '/attendance/getRetroactive',
    params: {
      pageNum,
      pageSize
    }
  })
}

export const insertRetroactive = ( retroactive: RetroactiveReq): Promise<ApiResponse<null>> => {
  return instance({
    method: 'post',
    url: '/attendance/retroactive',
    data: retroactive
  })
}
